package cn.net.dckj.web.controller.system;

import cn.net.dckj.common.annotation.Log;
import cn.net.dckj.common.core.controller.BaseController;
import cn.net.dckj.common.core.domain.AjaxResult;
import cn.net.dckj.common.core.page.TableDataInfo;
import cn.net.dckj.common.enums.BusinessType;
import cn.net.dckj.common.utils.poi.ExcelUtil;
import cn.net.dckj.system.domain.Ttt;
import cn.net.dckj.system.service.ITttService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 测试代码生成Controller
 *
 * @author dckj
 * @date 2019-10-14
 */
@Controller
@RequestMapping("/system/ttt")
public class TttController extends BaseController {
    private String prefix = "system/ttt";

    @Autowired
    private ITttService tttService;

    @RequiresPermissions("system:ttt:view")
    @GetMapping()
    public String ttt() {
        return prefix + "/ttt";
    }

    /**
     * 查询测试代码生成列表
     */
    @RequiresPermissions("system:ttt:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Ttt ttt) {
        startPage();
        List<Ttt> list = tttService.selectTttList(ttt);
        return getDataTable(list);
    }

    /**
     * 导出测试代码生成列表
     */
    @RequiresPermissions("system:ttt:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Ttt ttt) {
        List<Ttt> list = tttService.selectTttList(ttt);
        ExcelUtil<Ttt> util = new ExcelUtil<Ttt>(Ttt.class);
        return util.exportExcel(list, "ttt");
    }

    /**
     * 新增测试代码生成
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存测试代码生成
     */
    @RequiresPermissions("system:ttt:add")
    @Log(title = "测试代码生成" , businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Ttt ttt, List<MultipartFile> files) {
        return toAjax(tttService.insert(ttt, files));
    }

    /**
     * 修改测试代码生成
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Ttt ttt = tttService.selectTttById(id);
        mmap.put("ttt" , ttt);
        return prefix + "/edit";
    }

    /**
     * 修改保存测试代码生成
     */
    @RequiresPermissions("system:ttt:edit")
    @Log(title = "测试代码生成" , businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Ttt ttt) {
        return toAjax(tttService.updateTtt(ttt));
    }

    /**
     * 删除测试代码生成
     */
    @RequiresPermissions("system:ttt:remove")
    @Log(title = "测试代码生成" , businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tttService.deleteTttByIds(ids));
    }

    /**
     * 校验测试代码生成数据唯一性
     */
    @PostMapping("/checkUnique")
    @ResponseBody
    public String checkUnique(Ttt ttt) {
        return this.tttService.checkUnique(ttt);
    }
}
